How to convert the length of an attribute name into pixes

I'm trying to resize columns in an existing view, some of them I'm unable to see the full attribute name and would like to come up with an automated method for going from the length of an attribute name to the number of pixels to make the column width accordingly so I can see the full name of the attribute. Anyone done this already? Have the function? Is there a magic factor to use?


DOORSWizard - Thu Apr 26 18:46:11 EDT 2018

Re: How to convert the length of an attribute name into pixes
O.Wilkop - Fri Apr 27 04:30:50 EDT 2018

I don't think such a function already exists, I'd assume you have to create your own lookup table of letter -> amount of pixel (by manually counting the pixel per letter once) and then loop through your attribute name and add up the pixel count for each.

Re: How to convert the length of an attribute name into pixes
Mathias Mamsch - Fri Apr 27 05:44:37 EDT 2018

The problem you have is that the column titles use a dynamic font, i.e. every letter has a different width - therefore a simply factor will only do, if you take the maximum width. BUT: The font that is used in the column titles might not be the same for every client, therefore you will not get a perfect result.

There is a function in DXL to measure the width of the text rendered to a canvas. This combined with the correct font settings might bring you to your goal. Apart from that I think that the creator of the view should take care about the column widths. In addition a simple script listing you the attributes of the columns in a list, might be more simple - depending on your use case.

Regards, Mathias

Re: How to convert the length of an attribute name into pixes
DOORSWizard - Fri Apr 27 10:13:18 EDT 2018

Mathias Mamsch - Fri Apr 27 05:44:37 EDT 2018

The problem you have is that the column titles use a dynamic font, i.e. every letter has a different width - therefore a simply factor will only do, if you take the maximum width. BUT: The font that is used in the column titles might not be the same for every client, therefore you will not get a perfect result.

There is a function in DXL to measure the width of the text rendered to a canvas. This combined with the correct font settings might bring you to your goal. Apart from that I think that the creator of the view should take care about the column widths. In addition a simple script listing you the attributes of the columns in a list, might be more simple - depending on your use case.

Regards, Mathias

After some experimentation I settled on a factor of 6, basically taking the length of the column title and multiplying by 6 to get my pixel count. It does what I need, which is basically expand the size of every column in the view where I can't see the whole title (i.e attribute name is too long).